﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class teacher_courseInfo : System.Web.UI.Page
{
    db_course course = new db_course();
    protected void Page_Load(object sender, EventArgs e)
    {

        Server.Execute("checkStu.aspx");  // 此处用户权限验证
        
        if (!IsPostBack)
        {
            initCourseType();

            tb_courseId.Text = Request.QueryString["courseId"];
            ddl_courseType.SelectedValue = Request.QueryString["courseType"];
            tb_name.Text = Request.QueryString["courseName"];

            btn_search_Click(sender, e);
        }
    }



    private void initCourseType()
    {
        DataSet ds = new DataSet();
        ds = course.getCourseType();
        if (ds.Tables.Count != 0)
        {
            ddl_courseType.DataSource = ds.Tables[0].DefaultView;
            ddl_courseType.DataTextField = "typeName";
            ddl_courseType.DataValueField = "typeId";
            ddl_courseType.DataTextField.Trim();
            ddl_courseType.DataValueField.Trim();
            ddl_courseType.DataBind();
            ddl_courseType.Items.Insert(0, new ListItem("请选择课程类型", ""));
            ddl_courseType.Items[0].Selected = true;
        }
    }


    protected void btn_search_Click(object sender, EventArgs e)
    {
        string courseId = tb_courseId.Text;
        string courseType = ddl_courseType.SelectedValue;
        string courseName = tb_name.Text;
        string stuId = Session["stuID"].ToString();
        string time = ddl_time.SelectedValue;
        DataSet ds = course.selectUserCourseSell_search(stuId,courseId, courseType, courseName,time);

        //分页 开始 -------
        firstPage.NavigateUrl = null;
        prePage.NavigateUrl = null;
        nextPage.NavigateUrl = null;
        endPage.NavigateUrl = null;

        int CurPage;
        if (sender.GetType().Equals(new Button().GetType()))
        {
            CurPage = 1;
        }
        else
        {
            if (Request.QueryString["Page"] != null && Convert.ToInt32(Request.QueryString["Page"]) > 0)
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            else
                CurPage = 1;
        }
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables[0].DefaultView;
        ps.AllowPaging = true;
        //每个页面显示的条数
        ps.PageSize = 10;
        onePage.Text = ps.PageSize.ToString();
        //求数据的总数
        allMsg.Text = ps.DataSourceCount.ToString();
        ps.CurrentPageIndex = CurPage - 1;
        //求总页
        allPages.Text = ps.PageCount.ToString();
        nowPage.Text = CurPage.ToString();
        //将数据源与控件绑定
        courseList.DataSource = ps;
        courseList.DataBind();

        //上一页
        if (!ps.IsFirstPage)
        {
            firstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1&stuId=" + stuId + "&courseType=" + courseType + "&courseName=" + courseName
 + "&courseId=" + courseId;
            prePage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + "&stuId=" + stuId + "&courseType=" + courseType + "&courseName=" + courseName + "&courseId=" + courseId;
        }
        //下一页
        if (!ps.IsLastPage)
        {
            nextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + "&stuId=" + stuId + "&courseType=" + courseType + "&courseName=" + courseName + "&courseId=" + courseId;
            endPage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(ps.PageCount) + "&stuId=" + stuId + "&courseType=" + courseType + "&courseName=" + courseName + "&courseId=" + courseId;
        }
        //分页 结束 -------
    }
}

